home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / OOP.SWG / 0009_OOP-HTKY.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  4KB  |  107 lines

  1. {
  2. > Yes, event oriented Programming is very easy using OOP, but as it
  3. > comes to TVision, if you need to add your own events, you're stuck. I
  4. > just wanted to implement the Windows-style ALT-Press-ALT-Release
  5. > event, that activates the Window menu, and I'd had to modify the
  6. > Drivers.pas sourceFile to implement it, so I have to find other keys
  7. > to activate the menu bar :-(
  8.  
  9. this Really stimulated me so I sat down and implemented the following *without*
  10. messing around in DRIVERS.PAS in -believe it or not- 15 minutes!  :-)))
  11. }
  12. Program tryalt;
  13.  
  14. Uses drivers,Objects,views,menus,app,Crt;
  15.  
  16. Const altmask = $8;
  17. Var   k4017 : Byte Absolute $40:$17;
  18.  
  19. Type  tmyapp = Object (TApplication)
  20.         AltPressed,
  21.         IgnoreAlt: Boolean;
  22.         Constructor Init;
  23.         Procedure InitMenuBar; Virtual;
  24.         Procedure GetEvent (Var Event: TEvent); Virtual;
  25.         Procedure Idle; Virtual;
  26.       end;
  27.  
  28. { low-level Function; returns True when <Alt> is being pressed }
  29. Function AltDown: Boolean;
  30. begin
  31.   AltDown := (k4017 and altmask) = altmask
  32. end;
  33.  
  34. Constructor tmyapp.Init;
  35. begin
  36.   inherited init;
  37.   AltPressed := False;
  38.   IgnoreAlt := False
  39. end;
  40.  
  41. Procedure Tmyapp.InitMenuBar;
  42. Var
  43.   R: TRect;
  44. begin
  45.   GetExtent(R);
  46.   R.B.Y := R.A.Y + 1;
  47.   MenuBar := New (PMenuBar, Init(R, NewMenu (
  48.     NewSubMenu ('~≡~', hcNoConText, NewMenu (
  49.       NewItem ('~A~bout LA-Copy...', '', kbNoKey, cmQuit, hcNoConText,
  50.       NewLine (
  51.       NewItem ('~D~OS Shell', '', kbNoKey, cmQuit, hcNoConText,
  52.       NewItem ('E~x~it', 'Alt-X', kbAltX, cmQuit, hcNoConText,
  53.       nil))))),
  54.     NewSubMenu ('~R~ead', hcNoConText, NewMenu (
  55.       NewItem ('~D~isk...', 'F5', kbF5, cmQuit, hcNoConText,
  56.       NewItem ('~I~mage File...', 'F6', kbF6, cmQuit, hcNoConText,
  57.       NewItem ('~S~ector...', 'F7', kbF7, cmQuit, hcNoConText,
  58.       NewLine (
  59.       NewItem ('~F~ree up used memory', 'F4', kbF4, cmQuit, hcNoConText,
  60.       nil)))))),
  61.     (* more menus in the original :-) *)
  62.     nil)))));
  63. end;
  64.  
  65. { modified GetEvent to allow direct usage of Alt-Hotkey }
  66. Procedure tmyapp.GetEvent (Var Event: TEvent);
  67. begin
  68.   inherited GetEvent (Event);
  69.   if (Event.What and (evKeyboard or evMessage)) <> evnothing then
  70.     IgnoreAlt := True               { in Case of keypress or command ignore }
  71. end;                                { Until <Alt> next time released }
  72.  
  73. Procedure tmyapp.Idle;
  74. Var Event: TEvent;
  75. begin
  76.   inherited Idle;
  77.   if AltDown then                      { <Alt> key is down }
  78.     AltPressed := True                   { remember this }
  79.   else begin                           { <Alt> is released (again?) }
  80.     if AltPressed then begin             { yes, again. }
  81.       if not IgnoreAlt then begin        { but: did they use Alt-Hotkey? }
  82.         Event.What := evCommand;           { no, let's activate the menu! }
  83.         Event.Command := cmMenu;
  84.         PutEvent (Event)
  85.       end;
  86.     end;
  87.     AltPressed := False;                 { however, <Alt> is up again }
  88.     IgnoreAlt := False                   { so we don't need to ignore it }
  89.   end;                                   { the next time <Alt> is released }
  90. end;
  91.  
  92. Var myapp: tmyapp;     { create an Object of class 'tmyapp' }
  93.  
  94. begin
  95.   myapp.init;     { you know these three lines, don't you? <g> }
  96.   myapp.run;
  97.   myapp.done;
  98. end.
  99.  
  100. {
  101. For convenience I copied the first three menus from my diskcopy clone so don't
  102. get confused about the items :-).  This Program does not emulate Completely
  103. Windows' behaviour, however, it's a good start. Tell me if this is what you
  104. wanted! I didn't test it excessively but it does work in this fairly simple
  105. Program For activating menus by <Alt>. The only thing not implemented is
  106. 'closing' the menu bar by a second <Alt> stroke.
  107. }